exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  /**
   * 查询区域
   */
  queryAreaListAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const AreaService = _this.service('cms/AreaService');
      const res = yield AreaService.getAreaList();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this.json(aj);
    })();
  }
  /**
   * 查询所有区域（分页）
   *
   * @returns
   */
  queryAllAreaListAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const GetData = _this2.get('page,pageSize,area_name');
      console.log(11, GetData);
      const AreaService = _this2.service('cms/AreaService');
      const res = yield AreaService.getAreaAllList(GetData);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this2.json(aj);
    })();
  }
  /**
   * 获取所有区域全部
   *
   * @returns
   */
  queryAllAreaDataAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const AreaService = _this3.service('cms/AreaService');
      const res = yield AreaService.getAreaData();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this3.json(aj);
    })();
  }
  /**
   * 保存区域坐标信息
   *
   * @returns
   */
  saveAreaScopeAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const postData = _this4.post('id,scope_path,area_code,area_name,city_type,color');
      const AreaService = _this4.service('cms/AreaService');
      const res = yield AreaService.saveAreaScope(postData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this4.json(aj);
    })();
  }

  /**
   * 保存新区域
   */
  saveNewAreaAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const postData = _this5.post('area_code,area_name,city_type,parent,scope_path');
      const AreaService = _this5.service('cms/AreaService');
      const res = yield AreaService.saveNewArea(postData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this5.json(aj);
    })();
  }
  /**
   * 删除区域
   *
   */
  delAreaAction() {
    var _this6 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();

      const data = {
        id: _this6.post('id')
      };
      console.log('delt', data);
      const AreaService = _this6.service('cms/AreaService');

      if (data) {
        const result = yield AreaService.delArea(data);
        if (!result.error) {
          aj.success = result.success;
          aj.msg = result.msg;
          aj.result = result.result;
          return _this6.json(aj);
        } else {
          aj.success = false;
          aj.msg = '删除失败';
          return _this6.json(aj);
        }
      } else {
        aj.success = false;
        aj.msg = '请传入参数id';
        return _this6.json(aj);
      }
    })();
  }
  delAreaPathAction() {
    var _this7 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();

      const data = {
        id: _this7.post('id')
      };
      console.log('delt', data);
      const AreaService = _this7.service('cms/AreaService');

      if (data) {
        const result = yield AreaService.delAreaPath(data);
        if (!result.error) {
          aj.success = result.success;
          aj.msg = result.msg;
          aj.result = result.result;
          return _this7.json(aj);
        } else {
          aj.success = false;
          aj.msg = '删除失败';
          return _this7.json(aj);
        }
      } else {
        aj.success = false;
        aj.msg = '请传入参数id';
        return _this7.json(aj);
      }
    })();
  }

  quearCellByAreaIdAction() {
    var _this8 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = {
        id: _this8.get('id')
      };
      const AreaService = _this8.service('cms/AreaService');

      if (data) {
        const result = yield AreaService.quearCellByAreaId(data);
        if (!result.error) {
          aj.success = result.success;
          aj.msg = result.msg;
          aj.result = result.result;
          return _this8.json(aj);
        } else {
          aj.success = false;
          aj.msg = '查询失败';
          return _this8.json(aj);
        }
      } else {
        aj.success = false;
        aj.msg = '请传入参数id';
        return _this8.json(aj);
      }
    })();
  }

  queryAreaByParentIdAction() {
    var _this9 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = {
        parent_id: _this9.get('parent_id')
      };
      const AreaService = _this9.service('cms/AreaService');
      const result = yield AreaService.queryAreaByParentId(data);

      if (data) {
        if (result.error) {
          aj.success = false;
          aj.msg = '查询失败';
          return _this9.json(aj);
        } else {
          aj.result = result;
          return _this9.json(aj);
        }
      } else {
        aj.success = false;
        aj.msg = '请传入参数id';
        return _this9.json(aj);
      }
    })();
  }
};